#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n, m, C;
long long int F[10010];

int main()
{
	read(n);read(m);read(C);
	int v, w, d, temp;
	for (int i = 1; i <= n; i++) 
	{
		read(v); read(w); read(d);
		if(C < d*v) //看是否满足完全背包.
		{
			for (int j = v; j <= C; j++) 
				F[j] = F[j] > F[j-v] + w ? F[j] : F[j-v] + w;
		}
		else
		{
			temp = 1;
			while(temp <= d)
			{
				for (int j = C; j >= v*temp; j--) 
					F[j] = F[j] > F[j - v*temp] + w*temp ? F[j] : F[j - v*temp] + w*temp;
				d -= temp;
				temp <<= 1;
			}
			if(d > 0)
			{
				for (int j = C; j >= v*d; j--)
					F[j] = F[j] > F[j - v*d] + w*d ? F[j] : F[j - v*d] + w*d;
			}
		}
	}

	for (int i = 1; i <= m; i++) 
	{
		read(v); read(w); read(d);
		for (int j = C; j >= 0; j--) 
			for (int k = 0; k <= j; k++) 
				F[j] = F[j] > F[j - k] + ( v*k + w ) * k + d ? F[j] : F[j - k] + ( v*k + w ) * k + d;
	}

	printf("%lld", F[C]);
	return 0;
}
